<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
        $model = $this->getModel();
        $aut = new bgAuthorize();
       
        switch(JRequest::getVar('task')){
            case 'error':
                $row = JRequest::getVar('jform');
                $this->row = $row;
                /* checkbox MFAC */
                $list_mfac_check = '';
                $mfac = $model->getListMFAC();
                for($i = 0; $i < count($mfac); $i++){
                    if(isset($row["MFAC".$mfac[$i]->MFAC_CODE])){
                        $list_mfac_check .= ",".$row["MFAC".$mfac[$i]->MFAC_CODE];
                    }    
                }
                $this->list_mfac_check = substr($list_mfac_check,1);
                
                /* checkbox MOBJ */
                $list_mobj_check = '';
                $mobj = $model->getListMOBJ();
                for($i = 0; $i < count($mobj); $i++){
                    if(isset($this->row["MOBJ".$mobj[$i]->MOBJ_CODE])){
                        $list_mobj_check .= ",".$this->row["MOBJ".$mobj[$i]->MOBJ_CODE];
                    }    
                }
                $this->list_mobj_check = substr($list_mobj_check,1);
                
                /* checkbox MCON */
                $list_mcon_check = '';
                $mcon = $model->getListMCON();
                for($i = 0; $i < count($mcon); $i++){
                    if(isset($this->row["MCON".$mcon[$i]->MCON_CODE])){
                        $list_mcon_check .= ",".$this->row["MCON".$mcon[$i]->MCON_CODE];
                    }
                }
                $this->list_mcon_check = substr($list_mcon_check,1);
                
                
                // Get data from model
                $this->list_pede = $model->getListPede();
                $this->list_mfac = $model->getListMFAC();
                $this->list_mobj = $model->getListMOBJ();
                $this->list_mcon = $model->getListMCON();
                
                $this->setLayout('a01510');
                JToolBarHelper::save2copy('savetemp','非公開');
                JToolBarHelper::save('save','公開');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title( '活動情報作成','calendar.png' );
                
                break;
            
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->getActtFromID($cid);
                }else{
                    //die('Not found');
                    die("データは見つかりませんでした");
                }
                
                // Get data from model
                $this->list_pede = $model->getListPede();
                $this->list_mfac = $model->getListMFAC();
                $this->list_mobj = $model->getListMOBJ();
                $this->list_mcon = $model->getListMCON();
                
                $this->setLayout('a01520');
                JToolBarHelper::save2copy('savetemp','非公開');
                JToolBarHelper::save('save','公開');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title( '活動情報編集','user.png' );
                
                break;
            case 'add':
                $row = JRequest::getVar('jform');
                $this->row = $row;
                // Get data from model
                $this->list_pede = $model->getListPede();
                $this->list_mfac = $model->getListMFAC();
                $this->list_mobj = $model->getListMOBJ();
                $this->list_mcon = $model->getListMCON();
                
                $this->setLayout('a01510');
                
                JToolBarHelper::title( '活動情報作成','calendar.png' );
                JToolBarHelper::save2copy('savetemp','非公開');
                JToolBarHelper::save('save','公開');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
            break;
            
            case 'popup_ocba':
                
                /* set data from the model */
                $this->list_ocba = $model->getListOcba();
                 
                /* set layout */         
                $this->setLayout('popup_ocba');
                break;
                 
            default:
                             
                //search
                $this->filter = &JRequest::getVar('jform');
                //Kiem tra co quyen Edit
                //if($aut->checkEditOwn()){
//                    $this->filter['user_id'] = $aut->getUserID();
//                    $this->rows =& $model->getAllActivity($this->filter);
//                }else{
//                    $this->rows =& $model->getAllActivity($this->filter);
//                }
                $this->rows =& $model->getAllActivity($this->filter);
                                
                // Get data from the model
                $this->list_pref = $model->getListPref();
                $this->list_pede = $model->getListPede();
                $this->list_mfac = $model->getListMFAC();
                $this->list_mobj = $model->getListMOBJ();
                $this->list_mcon = $model->getListMCON();
                //$this->rows =& $model->getAllActivity($this->filter);
                $this->pagination =& $this->get('Pagination');
                //Get list Club type
                //$this->listclub =& $model->getAllClubType(); 
                
                
                $this->setLayout('a01500');
            
                JToolBarHelper::title( '活動情報管理','calendar.png' );
                
                if($aut->checkAdd()){
                     JToolBarHelper::addNew('add','作成');
                }
                
                if($aut->checkEdit() || $aut->checkEditOwn()){
                    JToolBarHelper::editList('edit', '編集');
                }
                
                if($aut->checkDelete()){
	                JToolBarHelper::deleteList('', 'remove','削除');
                }
                
                if($aut->getUserGroup() == '8' || $aut->getUserGroup() == '9' ){
                    JToolBarHelper::custom('export_csv','csv.png','CSV出力', 'CSV出力',false);
                }
                
                if($aut->getUserGroup() == '11' ){
                    JToolBarHelper::custom('export_csv_cc','csv.png','CSV出力', 'CSV出力',false);
                }
		}
        
		parent::display();
	}
}




